package com.manage.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.manage.common.R;
import com.manage.pojo.FlowerManage;
import com.manage.mapper.FlowerManageMapper;
import com.manage.service.FlowerManageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 */
@Service
public class FlowerManageServiceImpl extends ServiceImpl<FlowerManageMapper, FlowerManage> implements FlowerManageService {

    @Override
    public R register(FlowerManage flowerManage) {
        // 1.查询数据库判断用户是否存在
        FlowerManage manage = getOne(Wrappers.<FlowerManage>lambdaQuery().eq(FlowerManage::getUserAccount,flowerManage.getUserAccount()));
        if (manage != null){
            return R.error("用户名已经存在");
        }
        // 把用户存入数据库
        save(flowerManage);
        return R.success("注册成功！");
    }

    @Override
    public R login(FlowerManage flowerManage) {
        FlowerManage manage = getOne(Wrappers.<FlowerManage>lambdaQuery().eq(FlowerManage::getUserAccount,flowerManage.getUserAccount()));
        if (manage == null) {
            return R.error("登录失败！");
        }
        if (manage.getUserPassword().equals(flowerManage.getUserPassword())){
            return R.success(manage.getUserId(),"登录成功！");
        }
        return R.error("密码错误！");
    }
}
